package com.example.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.pojo.Customer;
import com.example.demo.service.CustomerService;
import com.example.demo.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjy
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/customer")
@Api(tags = "用户管理")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping("/customerLogin")
    @ApiOperation("用户登录接口")
    public ResultVO<Customer> customerLogin(String phone, String password) throws Exception {
        return customerService.customerLogin(phone, password);
    }

    @GetMapping("/customerRegister")
    @ApiOperation("用户注册接口")
    public ResultVO<Customer> customerRegister(Customer customer) throws Exception {
        return customerService.customerRegister(customer);
    }

    @GetMapping("/queryCustomer")
    @ApiOperation("查询用户")
    public ResultVO<IPage<Customer>> queryCustomer(String account, String name, String company, Integer state,Integer pageNum, Integer pageSize) throws Exception {
        return customerService.customerQuery(account,name,company,state,pageNum,pageSize);
    }

    @PostMapping("/updateCustomerState")
    @ApiOperation("更新客户账号状态")
    public ResultVO<Customer> updateCustomerState(Integer id,Integer state) throws Exception {
        return customerService.customerUpdateState(id,state);
    }

    @PostMapping("/recharge")
    @ApiOperation("用户充值接口")
    public ResultVO<Customer> recharge(Integer customerId, double amount) {
        return customerService.recharge(customerId, amount);
    }

    @GetMapping("/getBalanceById")
    @ApiOperation("根据用户ID获取余额")
    public ResultVO<Double> getBalanceById(Integer customerId) {
        return customerService.getBalanceById(customerId);
    }
}
